home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Procedure: importSkinMap
- //
- // Description:
- // This mel script is used to import a weight map for the skinning
- // data for each joint that affects the selected skin.
- //
- // To use, select the skin or skins, and type "importSkinMap"
- //
- //
-
- proc int checkForLattice(string $obj) {
-
- string $cpShape[] = `ls -type controlPoint $obj`;
- int $isLattice = 0;
- if (size($cpShape) > 0) {
- if (nodeType($obj) == "lattice") {
- $isLattice = 1;
- }
- } else {
- $cpShape = `listRelatives -pa -type controlPoint $obj`;
- for ($cp in $cpShape) {
- if (nodeType($cp) == "lattice") {
- $isLattice = 1;
- break;
- }
- }
- }
- if ($isLattice) {
- string $warnMsg = ("Skipping "+$obj+": Lattice maps are not supported by Artisan.");
- warning($warnMsg);
- }
- return $isLattice;
- }
-
- global proc int importSkinWeightMap(string $fileName, string $fileType)
- {
- if (`about -evalVersion`){
- // Because fopen and fprint are disabled in PLE,
- // importSkinWeightMap is not supported.
- warning ("importSkinWeightMap is not supported in Maya PLE.");
- return 0;
- }
-
- source "artAttrSkinCallback.mel";
- source "artAttrSkinJointMenu.mel";
-
- // Make sure we are in Skin Paint Weight Tool.
- string $currCtx = `currentCtx`;
- artAttrSkinToolScript 4;
-
- string $artCmd = "artAttrCtx -query -exportfiletype `currentCtx`";
- $fileType = eval( $artCmd );
-
- // Get the selected skins.
- int $skinCount = 0;
- int $latticeFound = 0;
- string $currentSelection[] = `ls -sl`;
- string $skins[];
- string $clusters[];
- for ($sel in $currentSelection) {
- if (checkForLattice($sel)) {
- $latticeFound = 1;
- continue;
- }
-
- // Find the cluster.
- string $buff[];
- tokenize($sel,".",$buff);
- string $cluster = findRelatedSkinCluster($buff[0]);
- if ("" != $cluster) {
- $skins[$skinCount] = $sel;
- $clusters[$skinCount] = $cluster;
- $skinCount++;
- }
- }
-
- if (0 == $skinCount) {
- if ($latticeFound) {
- error("Lattice maps are not supported by Artisan.");
- } else {
- error("No skins were selected.");
- }
- return 0;
- }
-
- $fileId = fopen( $fileName, "r" );
- if ($fileId == 0) {
- error("Unable to open the file: " + $fileName);
- return 0;
- }
-
- int $passed = 1;
-
- // Find the file and directory name.
- string $buff[];
- tokenize($fileName,"/",$buff);
- string $fn = $buff[size($buff)-1];
- tokenize($fn,"\\",$buff);
- $fn = $buff[size($buff)-1];
- $dir = substring($fileName,1,size($fileName)-size($fn));
- tokenize($fn,".",$buff);
- $fn = $buff[0];
- $dir += $fn;
-
- // Read in the master file that links the joint
- // names to the map names.
- string $skinNames[];
- string $jointNames[];
- string $fileNames[];
- string $clusterNames[];
- string $skinNamesForC[];
- int $lineCount = 0;
-
- string $nextLine = `fgetline $fileId`;
- while ( size( $nextLine ) > 0 ) {
- int $numTokens = tokenize($nextLine,$buff);
- if ($numTokens == 3) {
- $skinNames[$lineCount] = $buff[0];
- $jointNames[$lineCount] = $buff[1];
- $fileNames[$lineCount] = $buff[2];
- if (`objExists $buff[0]`) {
- string $relCluster = findRelatedSkinCluster($buff[0]);
- if ($relCluster != "") {
- int $found = 0;
- for ($clusterN in $clusterNames) {
- if ($clusterN == $relCluster) {
- $found = 1;
- break;
- }
- }
- if (! $found) {
- int $which = size($clusterNames);
- $clusterNames[$which] = $relCluster;
- $skinNamesForC[$which] = $buff[0];
- }
- }
- }
- $lineCount++;
- }
- $nextLine = `fgetline $fileId`;
- }
- if (catch(`fclose $fileId`)) {
- error("Unable to close the file: " + $fileName);
- $passed = 0;
- }
-
- // Import the maps for each joint.
- if ($passed) {
-
- int $counter;
- int $oldNormWeights[];
- for ($counter = 0; $counter < size($clusterNames); $counter++) {
- $oldNormWeights[$counter] = `getAttr ($clusterNames[$counter]+".normalizeWeights")`;
- setAttr ($clusterNames[$counter]+".normalizeWeights") 0;
- // set all weights to zero
- //
- skinPercent -prw 1.1 $clusterNames[$counter];
- }
-
- // Set the paint operation to 'replace'.
- artAttrCtx -e -selectedattroper "absolute" `currentCtx`;
-
- $skinCount = 0;
-
- for ($counter = 0; $counter < $lineCount; $counter++) {
- string $mapFn = ($dir+"/"+$fileNames[$counter]);
- string $jt = $jointNames[$counter];
- string $skin = $skinNames[$counter];
- if (`file -q -ex $mapFn`) {
- if (`objExists $jt` && `objExists $skin`) {
-
- // Make the joint a selected node.
- string $shortName = artAttrSkinShortName($jt);
- select -r $skin;
- artSkinSelectInfluence( "artAttrCtx", $jt, $shortName );
-
- // Get the cluster name.
- $artCmd = "artAttrCtx -q -objattrArray `currentCtx`";
- string $selectedAttr = eval( $artCmd );
-
- string $tmpName[];
- tokenize( $selectedAttr, ".", $tmpName );
- if ( size($tmpName) < 2 )
- continue;
-
- string $cluster = $tmpName[1];
-
- print("// Importing "+$fileNames[$counter]+" to ");
- print($skin+" for joint "+$jt+"\n");
-
- // Import the attribute map now.
- artAttrCtx -e -importfileload $mapFn `currentCtx`;
- getAttr -silent ($cluster+".og[0]");
- } else {
- if (! `objExists $jt`) {
- print("// Skipping "+$jt+": joint does not exist.\n");
- } else {
- print("// Skipping "+$skin+": skin does not exist.\n");
- }
- }
- } else {
- print("// Skipping "+$mapFn+": File not found.\n");
- }
- }
-
- for ($counter = 0; $counter < size($clusterNames); $counter++) {
-
- setAttr ($clusterNames[$counter]+".normalizeWeights") $oldNormWeights[$counter];
- select -r $skinNamesForC[$counter];
- skinPercent -normalize true $clusterNames[$counter];
- }
- }
-
- // Go back to the original context.
- setToolTo $currCtx;
- select -r $currentSelection;
-
- return $passed;
- }
-
- global proc importSkinMap( string $version, string $args[] ) {
-
- // set the fileBrowser directory to the images dir if it exists
- //
- string $imageDir = (`workspace -q -rd`+"sourceimages\/");
- if (`file -q -ex $imageDir`) {
- workspace -dir $imageDir;
- }
-
- // bring up the file browser dialog so that they can choose a file name
- //
- fileBrowser("importSkinWeightMap","Import Map","map",0);
- }
-